package com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.supplier;

import org.springframework.stereotype.Service;

import com.iwhalecloud.bss.kite.common.constant.SymbolConsts;
import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.custview.userinfo.UserAttrSupplier;

/**
 * @ClassName : UserLocationSupplier
 * @Description : 用户归属地属性提供者
 * @Author : xie.zhengjun
 * @Date : 2021/3/14 15:56
 */
@Service
@UserAttrSupplier(attrField = "user_location")
public class UserLocationSupplier extends AbstractUserAttrSupplier {
    @Override
    public String getValue() {
        String provinceCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "PROVINCE_CODE");
        String eparchyCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "EPARCHY_CODE");
        String cityCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "CITY_CODE");
        return String.join(SymbolConsts.HYPHEN, provinceCode, eparchyCode, cityCode);
    }

    @Override
    public String getValueDesc() {
        String provinceCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "PROVINCE_CODE");
        String eparchyCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "EPARCHY_CODE");
        String cityCode = KiteMapUtils.getString(userInfoContext.getUserInfo(), "CITY_CODE");
        return String.join(SymbolConsts.HYPHEN, LocalAttrHelper.getRegionName(provinceCode),
            LocalAttrHelper.getRegionName(eparchyCode), LocalAttrHelper.getRegionName(cityCode));
    }
}
